home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7641 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ccnet.com!usenet
  2. From: paulp@ccnet.com (Paul Pedriana)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Derived class not calling overloaded base class function
  5. Date: Sat, 24 Feb 1996 19:29:09 GMT
  6. Organization: Two-Bit Software
  7. Message-ID: <4gnp1m$q0m@ccnet2.ccnet.com>
  8. References: <4g46t2$3vd@otis.netspace.net.au>
  9. NNTP-Posting-Host: h96-194.ccnet.com
  10.  
  11. >I have a class, say 'foo' (everyone's favourite) which has a member function 
  12. >'int Get(void)'
  13.  
  14. >I then derive a class (say 'goo') which has as a base class foo. If goo has a 
  15. >function also called Get, but with different params (say ''char *Get(char *)') I can't 
  16. >seem to get the base class' Get() function to operate within the derived class.
  17.  
  18. >If I say just plain "Get()" it says too few parameters (for Get(char *)". If I use 
  19. >"::Get()" the compiler complains Get should have a prototype. If I say "foo.Get()" it 
  20. >says improper use of typedef foo. The only way seems to be to explicitly cast the 
  21. >this pointer to a foo.
  22.  
  23. >Surely there is a better way than this? Thanks for any help (e-mail preferred)
  24.  
  25. The effect you are seeing is called function hiding. If a subclass defines a
  26. function with the same name as any parent function, all parent functions with
  27. the same name are hidden and must be redeclared in the subclass. I forget the
  28. exact reason for this or the exact details of the implementation, so the experts
  29. can respond with more details. Your compiler should have generated warnings when
  30. compiling the subclass that it was hiding Get() from the parent class.
  31.  
  32. Paul Pedriana
  33. paulp@ccnet.com
  34.  
  35.